package copy.express.process.spit.impl;


import copy.express.pojo.Node;
import copy.express.pojo.type.Type;
import copy.express.process.spit.ConfirmTypeEndIndex;
import copy.tools.StringStrTools;

public class StringTypeEndIndex implements ConfirmTypeEndIndex {
    private static StringTypeEndIndex stringTypeEndIndex = new StringTypeEndIndex();

    protected StringTypeEndIndex() {
    }

    public static StringTypeEndIndex getInstance(){
        return stringTypeEndIndex;
    }

    @Override
    public boolean confirmType(char c) {
        String t = ""+c;
        if (t.equals("\'")){
            return true;
        }
        return false;
    }

    @Override
    public int findEndIndex(int start,int pos, char[] chars) {
        for (pos = start; pos < chars.length; pos++) {
            if ( confirmType(chars[pos])  ){
                return pos+1;
            }
        }
        return -1;
    }

    @Override
    public Node createNode(int start, int end, char[] chars) {
        String result = StringStrTools.appendFromStartToEnd(start+1,end-2,chars);
        return new Node(result, Type.StringType.DEFAULT);
    }
}
